import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/index', //重定向
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ('@/components/pulic/Login.vue')
    },
    {
        path: '/register',
        name: 'register',
        component: () =>
            import ('@/components/pulic/Register.vue')
    },
    {
        path: '/index',
        name: 'index',
        component: () =>
            import ('@/views/index/Index.vue')
    },
    {
        path: '/category',
        name: 'category',
        component: () =>
            import ('@/views/category/Category.vue')
    },
    {
        path: '/about',
        name: 'about',
        component: () =>
            import ('@/views/about/About.vue')
    },
    {
        path: '/contact',
        name: 'contact',
        component: () =>
            import ('@/views/contact/Contact.vue')
    },
    {
        path: '/details/:id',
        name: 'details',
        component: () =>
            import ('@/components/pulic/Details.vue')
    },
    // 以下路由需要登录验证
    {
        path: '/cart',
        name: 'cart',
        meta: { requiresAuth: true },
        component: () =>
            import ('@/components/private/Cart.vue'),
    },
    {
        path: '/checkstand',
        name: 'checkstand',
        meta: { requiresAuth: true },
        component: () =>
            import ('@/components/private/Checkstand.vue'),
    },
    {
        path: '/personal',
        name: 'personal',
        redirect: '/order',
        meta: { requiresAuth: true },
        component: () =>
            import ('@/components/private/Personal.vue'),
        children: [{
                path: '/myinfo',
                name: 'myinfo',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Myinfo.vue')
            },
            {
                path: '/order',
                name: 'order',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Order.vue')
            },
            {
                path: '/address',
                name: 'address',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Address.vue')
            },
            {
                path: '/changepassword',
                name: 'changepassword',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Changepassword.vue')
            },
            {
                path: '/customer',
                name: 'customer',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Customer.vue')
            },
            {
                path: '/myorder',
                name: 'myorder',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Myorder.vue')
            },
            {
                path: '/managedmybook',
                name: 'managedmybook',
                meta: { requiresAuth: true },
                component: () =>
                    import ('@/components/personal/Managedmybook.vue')
            },
        ]
    },
]

const router = new VueRouter({
    routes
})

export default router